package com.seed.commons.util;

import java.io.File;
import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

public class BaseUtil {
	
	private static Log log = LogFactory.getLog(BaseUtil.class) ;
	
	/**
	 * 获得当前项目的所在绝对路径 
	 * @return
	 * @throws IOException
	 */
	public static String getProjectPath(){
		return System.getProperty("user.dir") ;
	}
	
	/**
	 * 生成Document并加载XML文档
	 * @param path
	 * @return Document
	 */
	public static Document getDocument(String path) {
		SAXReader reader = new SAXReader() ;
		
		if(null != path && !"".equals(path)) {
			Document document = null ;
			try {
				document = reader.read(new File(path));
			} catch (DocumentException e) {
				log.info("加载XML生成Document错误：" + e.getMessage()) ;
				return null;
			}
			return document ;
		}
		log.info("XML文档路径不能为空！") ;
		
		return null ;
	}
	
	
	
	public static void main(String[] args) throws IOException {
		System.out.println(getDocument(""));
	}
	
}
